module utils.Singleton;



template SingletonMix() {
	static typeof(this) singletonInstance;

	this() {
		assert (singletonInstance is null);
		singletonInstance = this;
	}
}


T SingletonGetter(T)() {
	if (T.singletonInstance is null) {
		new T;
		assert (T.singletonInstance !is null);
		static if (is(typeof(T.singletonInstance.initialize))) {
			T.singletonInstance.initialize();
		}
	}
	return T.singletonInstance;
}
